//
//  MyTopView.swift
//  Venus
//
//  Created by qurongxiang on 2018/7/23.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit

class MyTopView: UIView {
    
    fileprivate lazy var waterWaveView:DCWaterWaveView = DCWaterWaveView(frame: CGRect(x: 0, y:100, width: kScreenW -  40, height: 60))
    lazy var headImgView = UIImageView()
    lazy var titleLabel =  UITextField()
    lazy var showNumLabel = UILabel(kColorC5, 14, "剩余查看次数 0")
    fileprivate lazy var progressView = ShowNumProgressView(frame: CGRect.zero)
    
    lazy var btn = UIButton(type: .custom)
    
    lazy var applybtn = UIButton(type: .custom)
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func start() {
        waterWaveView.start()
    }
    
    func stop() {
        waterWaveView.stop()
    }
    
    func config(num:Int) {
        progressView.config(num: num)
    }
    
}

extension MyTopView {
    func configModel(userModel: MyUserModel){
        titleLabel.text = userModel.userName
        if userModel.headImg.count > 0 {
            headImgView.showImageS(userModel.headImg)
        }
        
        if userModel.jobName.count > 0 {
            applybtn.setTitle("已经认证", for: .normal)
        }else {
            if userModel.haveApply {
                applybtn.setTitle("等待审核中", for: .normal)
            }else {
                applybtn.setTitle("申请认证", for: .normal)
            }
        }
    }
}

extension MyTopView {
    func setupUI() {
        
        addSubview(headImgView)
        addSubview(titleLabel)
        addSubview(progressView)
        addSubview(showNumLabel)
        addSubview(btn)
        
        headImgView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 60, height: 60))
            make.top.equalTo(self).offset(20)
            make.left.equalTo(self).offset(20)
        }
        headImgView.fastCornerRadius(value: 30)
        
        
        titleLabel.text = "我的名字"
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(headImgView.snp.top)
            make.left.equalTo(headImgView.snp.right).offset(20)
            make.width.equalTo(200)
        }
        titleLabel.font = UIFont.systemFont(ofSize: 14)
        
        
        headImgView.showImageS(UserInfo.shareInstance.userModel().headImg)
        if UserInfo.shareInstance.userModel().userName.count > 0 {
            titleLabel.text =  UserInfo.shareInstance.userModel().userName
        }
        
        progressView.snp.makeConstraints { (make) in
            make.width.equalTo(129)
            make.height.equalTo(8)
            make.left.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(10)
        }
        
        
        
        showNumLabel.snp.makeConstraints { (make) in
            make.top.equalTo(progressView.snp.bottom).offset(10)
            make.left.equalTo(titleLabel)
        }
        
        btn.setTitle("兑换", for: .normal)
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        btn.fastCornerRadius(value: 4)
        btn.backgroundColor = UIColor(hex: "f68859")
        btn.isUserInteractionEnabled = false
        btn.snp.makeConstraints { (make) in
            make.centerY.equalTo(progressView)
            make.left.equalTo(progressView.snp.right).offset(20)
            make.size.equalTo(CGSize(width: 45, height: 30))
        }
        
        addSubview(applybtn)
        applybtn.isHidden = true
        applybtn.setTitle("申请认证", for: .normal)
        applybtn.backgroundColor = UIColor(hex: "f68859")
        applybtn.snp.makeConstraints { (make) in
            make.top.equalTo(showNumLabel.snp.bottom).offset(10)
            make.left.equalTo(showNumLabel.snp.left)
            make.size.equalTo(CGSize(width: 80, height: 20))
        }
        
        applybtn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        applybtn.fastCornerRadius(value: 10)
        
        backgroundColor = UIColor.yellow
        addSubview(waterWaveView)
        waterWaveView.clipsToBounds = true
        titleLabel.isUserInteractionEnabled = true
        headImgView.isUserInteractionEnabled = true
    }
}
